from time import time, strftime, localtime

from itemloaders.processors import TakeFirst, MapCompose
from scrapy.loader import ItemLoader


def time_sec2str(sec):
    '''
        数字时间（10位秒为单位）转换为时间字符串
    :param sec: 秒
    :return:    时间字符串
    '''
    print(sec, '='*10)
    if not sec:
        return strftime('%Y-%m-%d %H:%M:%S', time())
    return strftime('%Y-%m-%d %H:%M:%S', localtime(sec))


class XpcWorkLoader(ItemLoader):
    default_output_processor = TakeFirst()
    publish_time_out = MapCompose(time_sec2str)
